#include <iostream>
#include <stdexcept>
#include "Date.h"

Date::Date( int mn, int dy, int yr){
	if ( mn > 0 && mn <= monthPerYear){
		month = mn;}
		else
			throw std::invalid_argument ( " mont must be 1 - 12 ");

	year = yr;
	day = checkDay(dy);

	std::cout << " Date object constructor for date ";
	print();
	std::cout << std::endl;
}

void Date::print() const {
	std::cout << month << "/" << day << "/" << year;
	std::cout << std::endl;
}
Date::~Date(){
	std::cout << " Data object destructor for date ";
	print();
	std::cout << std::endl;
}

int Date::checkDay (int testDay) const
{
	static const int daysPerMonths[ monthPerYear + 1] =
	{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

	if ( testDay > 0 && testDay <= daysPerMonths[ month ]){
		return testDay; }
	if ( testDay > 0 && testDay == 29 && ( year % 400 ==0 || ( year % 4 == 0 && year % 100 != 0 ) ) ){
		return testDay;
	}
	throw std::invalid_argument ( " Invalid date ");
}
